package cn.wit.summit.chwan.widgets;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.Window;
import android.widget.TextView;

import cn.wit.summit.chwan.R;


/**
 * @author 彭少奎
 * @see ，可设置标头文字和按钮点击事件
 */
public class LodingDialog extends Dialog {

    boolean canclable = false;
    String text;
    TextView textView;

    protected LodingDialog(Context context, boolean cancelable,
                           OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }

    public LodingDialog(Context context) {

        super(context);
    }

    public LodingDialog(Context context, int theme) {
        super(context, theme);
    }

    public LodingDialog(Context context, int theme, boolean canclable) {
        super(context, theme);
        this.canclable = canclable;
    }

    public LodingDialog(Context context, int theme, String text) {
        super(context, theme);
        this.canclable = canclable;
        this.text = text;
    }

    public LodingDialog(Context context, int theme, String text, boolean canclable) {
        super(context, theme);
        this.canclable = canclable;
        this.text = text;
    }


    public void setText(String text) {
        if (textView != null) {
            textView.setText(text);
        }
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        Window dialogWindow = getWindow();
        dialogWindow.setBackgroundDrawableResource(android.R.color.transparent);
        dialogWindow.setGravity(Gravity.CENTER);
        this.setContentView(R.layout.loding_layout);
        setCancelable(canclable);
        textView = (TextView) findViewById(R.id.textView);
        if (!TextUtils.isEmpty(text)) {
            textView.setText(text);
        }


    }

    public void showdialog() {
        try {
            if (!isShowing()) {
                show();
            }
        } catch (Exception e) {
        }
    }


}
